package com.example.hissys.mapper;

import com.example.hissys.entity.User;
import org.apache.ibatis.annotations.*;

@Mapper
public interface UserMapper {

    // 用户注册
    @Insert("INSERT INTO users (username, password, phone) VALUES (#{username}, #{password}, #{phone})")
    @Options(useGeneratedKeys = true, keyProperty = "id")
    int register(User user);

    // 用户登录
    @Select("SELECT * FROM users WHERE username = #{username} AND password = #{password}")
    User login(@Param("username") String username, @Param("password") String password);

    // 检查用户名是否存在
    @Select("SELECT COUNT(*) FROM users WHERE username = #{username}")
    int checkUsernameExists(@Param("username") String username);

    /**
     * 根据用户名查询用户ID
     * @param username 用户名
     * @return 用户ID
     */
    @Select("SELECT id FROM users WHERE username = #{username}")
    Integer findIdByUsername(String username);
}
